from flask import Flask
from flask_cors import CORS
from flask_migrate import Migrate
from models import db
from views.users import user_bp
from views.channel import channel
from views.comments import comment_bp
from views.new import new_bp
from common.utils.jwt_auth import jwt_authentication


def create_flask_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    db.init_app(app)
    CORS(app)
    # 使用请求钩子验证token
    Migrate(app, db)
    app.before_request(jwt_authentication)
    # 注册蓝图
    app.register_blueprint(user_bp)
    app.register_blueprint(channel)
    app.register_blueprint(comment_bp)
    app.register_blueprint(new_bp)
    return app
